package com.lemon.smartsafetynew.ui.activity.incident;

import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.app.AppManager;
import com.lemon.smartsafetynew.ui.activity.base.SwipeBackActivity;
import com.lemon.smartsafetynew.ui.fragment.incident.IncidentListFragment;

import butterknife.Bind;

/**
 * Created by Andrew on 2017/9/6.
 */

public class IncidentHomeActivity extends SwipeBackActivity {

    @Bind(R.id.tabLayout)
    TabLayout tabLayout;
    @Bind(R.id.viewPager)
    ViewPager viewPager;

    @Override
    protected void initTitle() {
        this.setBarTitle(R.string.work_options_main_6);
    }

    @Override
    protected void callFinish() {
        AppManager.getAppManager().finishActivity(this);
    }

    @Override
    protected int getContentViewId() {
        return R.layout.activity_viewpage_tab_layout;
    }


    @Override
    protected void initViews() {
        super.initViews();

        // ======= 该变指示栏的长度 =======
        tabLayout.post(new Runnable() {
            @Override
            public void run() {
                setIndicator(tabLayout, 10, 10); //左右各缩进5dp
            }
        });

        // ======= 该变指示栏的长度 =======
        viewPager.setAdapter(new IncidentViewpagerAdapter(getSupportFragmentManager()));
        tabLayout.setupWithViewPager(viewPager);

    }

    private class IncidentViewpagerAdapter extends FragmentStatePagerAdapter {

        public IncidentViewpagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return IncidentListFragment.newInstance(String.valueOf(position));  //TODO
        }

        @Override
        public int getCount() {
            return 2;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            switch (position) {
                case 0:
                    return getString(R.string.incident_home_tab_1);
                case 1:
                    return getString(R.string.incident_home_tab_2);
            }
            return null;
        }

    }

}
